'use strict';
'require view';
'require fs';
'require rpc';
'require validation';
'require ui';
var callPortsInfoDump = rpc.declare({
	object: 'network.device',
	method: 'status',
	expect: {}
});

function getPortsInfo() {
	return L.resolveDefault(callPortsInfoDump(), {})
		.then(function(res) {
			console.log(res);
			var data=[];
			
			Object.entries(res).forEach(([key, value]) => {
				console.log(key, value);  //输出对象的键
				switch(key){
					case "eth1":
					case "lan1":
					case "lan2":
					case "lan3":
					case "lan4":
					case "lan5":
						data.push({name: key, speed: value.speed, rx_bytes: value.statistics.rx_bytes, tx_bytes: value.statistics.tx_bytes})
						break;
				}
				
			});


			return data;
		});
}
return view.extend({
	load: function() {
		return getPortsInfo();
	},
	buttonClick: function(){},
	render: function(data) {
		
		var table = E('table', {
			'class': 'table assoclist',
			'id': 'wifi_assoclist_table'
		}, [E('tr', {
			'class': 'tr table-titles'
		}, [E('th', {
			'class': 'th nowrap'
		}, _('设备名称')), E('th', {
			'class': 'th hide-xs'
		}, _('网口速率')), E('th', {
			'class': 'th'
		}, _('接收字节')), E('th', {
			'class': 'th'
		}, _('发送字节')), E('th', {
			'class': 'th'
		}, _('电源开关'))])]);
		cbi_update_table(table, [], E('em', {
			'class': 'spinning'
		}, _('Collecting data...')))
		
		cbi_update_table(table, data.map(L.bind(function(device) {
			var rows = [device.name, device.speed, device.rx_bytes, device.tx_bytes];
			rows.push(E('button',{
				'class': 'cbi-button cbi-button-apply',
				'click': L.bind(this.buttonClick, this, null)
			},[_('打开电源')]))
			return rows;
		}, this)), E('em', _('There are no active leases')));
		
		
		return E([E('h3', _('Associated Stations')), table]);
	},
	handleSaveApply: null,
	handleSave: null,
	handleReset: null
});